package com.xuxk.project.library.controller.api;

import com.github.pagehelper.Page;
import com.xuxk.project.library.annotation.LibraryLog;
import com.xuxk.project.library.bean.XuxkBooking;
import com.xuxk.project.library.service.XuxkBookingService;
import com.xuxk.project.library.util.PageInfoVo;
import com.xuxk.project.library.util.PageUtil;
import com.xuxk.project.library.util.RequestUtils;
import com.xuxk.project.library.util.ResultBodyVo;
import com.xuxk.project.library.vo.XuxkBookingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 *   @author  橙云科技有限公司
 */

@RequestMapping("/api/xuxkBooking")
@RestController
public class XuxkBookingController  {

    @Autowired
	XuxkBookingService xuxkBookingService;


    /**
    * 分页查询
    * @param pageNum  页码
    * @param pageSize 页行数
    * @param request
    * @return
    */
    @GetMapping(value = "/v1.0/xuxkBookings", produces = MediaType.APPLICATION_JSON_VALUE)
    @LibraryLog(eventName = "分页查询书本信息列表")
	public ResultBodyVo xuxkBookings(Integer pageNum, Integer pageSize, HttpServletRequest request){

        Map<String,Object> paramMap = RequestUtils.getQueryParams(request);
        Page<XuxkBookingVo> pageResult = xuxkBookingService.listXuxkBookings(paramMap, PageUtil.getPageParam(pageNum,pageSize));

		return new ResultBodyVo(new PageInfoVo(pageResult)) ;
	}



    @GetMapping(value="/v1.0/xuxkBookings/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    @LibraryLog(eventName = "获取书本信息")
    public ResultBodyVo getXuxkBooking(@PathVariable Integer id) {
        XuxkBooking xuxkBooking = xuxkBookingService.getXuxkBooking(id);

        return new ResultBodyVo(xuxkBooking);
    }


    @PostMapping(value="/v1.0/xuxkBookings", produces = MediaType.APPLICATION_JSON_VALUE)
    @LibraryLog(eventName = "新增书本信息")
    public ResultBodyVo saveXuxkBooking(@RequestBody XuxkBooking xuxkBooking) {
        return  new ResultBodyVo(xuxkBookingService.insertXuxkBooking(xuxkBooking));

    }


    @PatchMapping(value="/v1.0/xuxkBookings/{id}", produces = MediaType.APPLICATION_JSON_VALUE)

    public ResultBodyVo patchUpdateXuxkBooking(@PathVariable Integer id,@RequestBody XuxkBooking xuxkBooking) {
        xuxkBooking.setId(id);
        return  new ResultBodyVo(xuxkBookingService.patchUpdateXuxkBooking(xuxkBooking));


    }

    @PutMapping(value="/v1.0/xuxkBookings/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultBodyVo updateXuxkBooking(@PathVariable Integer id,@RequestBody XuxkBooking xuxkBooking) {

        xuxkBooking.setId(id);
        return new ResultBodyVo(xuxkBookingService.updateXuxkBooking(xuxkBooking));
    }


    @DeleteMapping(value="/v1.0/xuxkBookings/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultBodyVo deleteXuxkBooking(@PathVariable Integer id) {

         xuxkBookingService.deleteXuxkBooking(id);

        return new ResultBodyVo("删除成功！") ;

    }

}
